import { SceneLoader, Scene } from '@babylonjs/core';
import '@babylonjs/loaders/glTF';

/**
 * 加载3D模型到场景
 * @param scene 要加载模型的场景
 * @param rootUrl 模型文件根路径
 * @param fileName 模型文件名
 * @returns 返回加载完成的Promise
 */
export async function loadModel(scene: Scene, rootUrl: string, fileName: string): Promise<void> {
  return new Promise((resolve, reject) => {
    SceneLoader.ImportMesh('', rootUrl, fileName, scene, 
      (meshes) => {
        // 处理模型加载成功
        console.log(`成功加载了${meshes.length}个网格`);
        resolve();
      },
      null,
      (scene, message, exception) => {
        // 处理加载失败
        console.error(`模型加载失败: ${message}`);
        reject(new Error(message));
      }
    );
  });
} 